/******************************************************************************
**                                                                           **
**                 Proprietary and Confidential Information                  **
**                                                                           **
**             Copyright (c) Conexant Systems, Inc. Unpublished              **
**                                                                           **
** This source code and the algorithms implemented therein constitute        **
** confidential information and may compromise trade secrets of Conexant     **
** Systems, Inc. or its associates, and any unauthorized use thereof is      **
** prohibited.                                                               **
**                                                                           **
******************************************************************************/

#ifndef __dc_raster_api_h__
#define __dc_raster_api_h__

#include "dc_type.h"
#include "tx_api.h"
#include "dc_image_api.h"
#include "dc_imgbuf_api.h"
#include "zlib.h"

#define DC_RASTER_STACK_BYTES 32000

typedef enum {
  DC_RASTER_CALLBACK_REASON_needData,
  DC_RASTER_CALLBACK_REASON_error,
  DC_RASTER_CALLBACK_REASON_done,
  DC_RASTER_CALLBACK_REASON__last,
} DC_RASTER_CALLBACK_REASON_t;

typedef enum {
  DC_RASTER_PHOTOMETRIC_DigiColor,
  DC_RASTER_PHOTOMETRIC_Standard,
  DC_RASTER_PHOTOMETRIC__last,
} DC_RASTER_PHOTOMETRIC_t;

typedef void (*DC_RASTER_CALLBACK_FCN)
     ( DC_RASTER_CALLBACK_REASON_t reason,
       UINT32 userCallbackArg,
       UINT32 arg0,
       UINT32 arg1 );

typedef void* (*DC_RASTER_ALLOC_FCN)
     ( void *opaque,
       unsigned int items,
       unsigned int size );

typedef void (*DC_RASTER_FREE_FCN)
     ( void *opaque,
       void *address );

typedef struct _dc_raster_struct {

#ifndef _WIN32
  // resources for dc_raster thread
  TX_THREAD thread;
  TX_EVENT_FLAGS_GROUP flags;
  ULONG stack[DC_RASTER_STACK_BYTES/sizeof(ULONG)];
#endif

  // callback function and user argument
  DC_RASTER_CALLBACK_FCN callback;
  UINT32 userCallbackArg;

  // functions for memory alloc/free
  DC_RASTER_ALLOC_FCN usermem_alloc;
  DC_RASTER_FREE_FCN usermem_free;
  void *usermem_opaque;

  // image info
  int version;
  int width;
  int height;
  DC_IMAGE_CHANNELS channels;
  DC_IMAGE_FORMAT format;
  int object;
  int deflate;

  // zlib stream
  int deflateWindowSize;
  z_stream stream;  

  // raw zlib output window
  struct {
    UINT8 *base;
    UINT32 rdPtr, wrPtr, avail, end;
  } window;
  
  // rgb/k buffer info
  DC_IMGBUF * rgbImgBuf;
  DC_IMGBUF_PRODUCER rgbProducer;
  UINT32 rgbBase, rgbStride, rgbYSize, rgbYValue;

  // extent buffer
  DC_CIRCBUF *extBuf;
  DC_CIRCBUF_PRODUCER extProducer;
  UINT32 extBase, extStride, extSize, extYValue;
  int preFillWithBlank;
  int skipBlank;
  int consecutiveBlank;

  // content type buffer info
  DC_IMGBUF *objBuf;
  DC_IMGBUF_PRODUCER objProducer;
  UINT32 objBase, objStride, objYSize, objYValue;

  // photometric interpretation dependencies
  DC_RASTER_PHOTOMETRIC_t photometric;
  void (* windowCopyData)(struct _dc_raster_struct * raster, UINT8 *dest, UINT32 len);
  int whiteIs0;
  int doInvert;
  UINT32 white;

  // flag indicating that should follow printer API container rules
  int prapi;

  // ThreadX thread priority and time slice
  UINT32 priority, time_slice;

} DC_RASTER_t;


DC_RETURN_CODE dc_raster_create
( DC_RASTER_t *raster,
  DC_RASTER_CALLBACK_FCN callback,
  UINT32 userCallbackArg,
  DC_RASTER_ALLOC_FCN usermem_alloc,
  DC_RASTER_FREE_FCN usermem_free,
  void *usermem_arg );

DC_RETURN_CODE dc_raster_info_get
( DC_RASTER_t *raster,
  UINT32 *width,
  UINT32 *height,
  DC_IMAGE_CHANNELS *channels,
  DC_IMAGE_FORMAT *format,
  int *contentType );

DC_RETURN_CODE dc_raster_photometric_set ( DC_RASTER_t *raster, DC_RASTER_PHOTOMETRIC_t photometric);

DC_RETURN_CODE dc_raster_prapi_set ( DC_RASTER_t *raster, UINT32 prapi);

DC_RETURN_CODE dc_raster_priority_set ( DC_RASTER_t *raster, UINT32 priority, UINT32 time_slice);

DC_RETURN_CODE dc_raster_start
( DC_RASTER_t *raster,
  DC_IMGBUF *rgb,
  DC_CIRCBUF *extent,
  DC_IMGBUF *contentType,
  int preFillWithBlank,
  int skipBlank );

DC_RETURN_CODE dc_raster_thread_get ( DC_RASTER_t *raster, TX_THREAD **thread);

DC_RETURN_CODE dc_raster_cancel
( DC_RASTER_t *raster );

DC_RETURN_CODE dc_raster_delete
( DC_RASTER_t *raster );

#endif
